<?php

/*
  VoIP Wholesale 1.0
  ------------------
  Document   : module_external_home
  Created on : Sep 14, 2011, 4:32:27 PM
  Author     : Milos Jovanovic <miloscode@gmail.com>
  Description:

 */
?>
<div id="page-title"><?=lang('term_origin_trunks')?></div>

<div id="page-desc"><?=lang('text_origin_trunks_desc')?></div>

<div class="ui-widget"> 
    <div id="content">
        <!-- PAGE CONTENT -->
        <div class="module-options">
            <button id="module-add-origin-trunk"><?=lang('button_add_new_origin_trunk')?></button>
        </div>
        
        <fieldset class="ui-widget-content ui-state-active">

            <legend class="ui-widget-content ui-state-active"><?=lang('form_filters')?></legend>
                
            <form action="<?=MODULE_SITE_URL?>/origin/" method="post">
                <table>
                <tr>
                    <td>
					<?php 
					if(isset($carrier_id) && @$carrier_id != "none"){
					$posted_carrier_id = $carrier_id;
					$extra_css = "ui-state-error";
					}
					else
					{
					$posted_carrier_id = "";
					$extra_css = "";
					}?>
					<?=$this->APPLICATION->app_carriers->generate_menu('we_sell_to_them',"data[carrier_id]",$posted_carrier_id,"carrier ".$extra_css)?>
                    </td>
                    <td>
                            <input type="text" name="data[short_name]" value="<?php if(isset($short_name) && strlen($short_name)>0 && strtoupper($short_name) != strtoupper(lang('term_short_name'))){print $short_name;}else{print lang('term_short_name');}?>" id="short_name_field" <?php if(isset($short_name)  && strlen($short_name)>0 && strtoupper($short_name) != strtoupper(lang('term_short_name'))){?>class="ui-state-error"<?php }?>/>
                    </td>
                    <td>
                        <select name="data[status]" <?php if(isset($status) && @$status != "none"){?>class="ui-state-error"<?php }?>>
                            <option value="none"><?=lang('form_status')?></option>
                            <option value="all" <?php if(@$status == "all"){?>selected="selected"<?php }?>><?=lang('term_all')?></option>
                            <option value="active" <?php if(@$status == "active"){?>selected="selected"<?php }?>><?=lang('term_active')?></option>
                            <option value="inactive" <?php if(@$status == "inactive"){?>selected="selected"<?php }?>><?=lang('term_inactive')?></option>					
                        </select>
                    </td>
                    <td>
                        <select name="data[num_of_results]" <?php if(isset($num_of_results) && @$num_of_results != "none"){?>class="ui-state-error"<?php }?>>
                            <option value="none"><?=lang('form_max_results')?></option>
                            <option value="20" <?php if(@$num_of_results == "20"){?>selected="selected"<?php }?>>20</option>
                            <option value="50" <?php if(@$num_of_results == "50"){?>selected="selected"<?php }?>>50</option>
                            <option value="100" <?php if(@$num_of_results == "100"){?>selected="selected"<?php }?>>100</option>
                            <option value="200" <?php if(@$num_of_results == "200"){?>selected="selected"<?php }?>>200</option>
                            <option value="500" <?php if(@$num_of_results == "500"){?>selected="selected"<?php }?>>500</option>
                        </select>
                    </td>
                    <td>
                            <button id="filter-submit"><?=lang('term_search')?></button>
                    </td>
                </tr>
                </table>
            </form>                
        </fieldset>
        <br />
        <!-- table with the entries -->
	<table class="ui-widget ui-widget-content module-table-origin-trunks" id="module-carriers-table"> 
		<thead> 
			<tr class="ui-widget-header "> 
				<!--<th class="module-1st">#</th> -->
				<th class="module-2nd"><?=lang('term_carrier')?></th> 
                <th class="module-3rd"><?=lang('term_short_name')?></th> 
				<th class="module-4th"><?=lang('term_cli_guaranteed')?></th> 												
				<th class="module-5th"><?=lang('term_routing_family')?></th> 												
				<th class="module-6th"><?=lang('term_exceptions')?></th> 												
                <th class="module-7th"></th> 
				<th class="module-8th"></th>
				<th class="module-9th"></th>				
				<th class="module-10th"></th>				
			</tr> 
		</thead> 
		<tbody> 
		<?php $num=1;
		if(@is_array($trunks)){
		foreach($trunks as $trunk){
		$carrier = $this->PACKAGE->routing->carriers->get_carrier_as_array_by_id($trunk['carrier_id']);
		$routing_family = $this->PACKAGE->routing->trunks->get_family_as_array_by_id($trunk['routing_family_id']);
		$exceptions = $this->PACKAGE->routing->trunks->calculate_exceptions($trunk['id']);
		?>
			<tr id="anchor_<?=$trunk['id']?>"> 
                <!--<td><?=$num?></td>-->
                <td class="module-2nd status_<?=$trunk['trunk_status']?> trunk_no_<?=$trunk['id']?>"><a href="<?=SITE_URL?>/carriers/#<?=$carrier['id']?>"><?=$carrier['username']?></a></td> 
                <td class="module-3rd status_<?=$trunk['trunk_status']?> trunk_no_<?=$trunk['id']?>"><?=$trunk['short_name']?></td> 
				<td class="module-4th status_<?=$trunk['trunk_status']?> trunk_no_<?=$trunk['id']?>"><?php if($trunk['cli_guaranteed']){?>yes<?php } else{?>no<?php }?></td>
				<td class="module-5th status_<?=$trunk['trunk_status']?> trunk_no_<?=$trunk['id']?>"><?php if(isset($routing_family['short_name'])){?><?=$routing_family['short_name']?><?php } else{?>--<?php }?></td> 				
				<td class="module-6th status_<?=$trunk['trunk_status']?> trunk_no_<?=$trunk['id']?>"><?php if(@$exceptions > 0){?><?=$exceptions?><?php } else {?>--<?php }?></td> 				
				<td class="module-7th status_<?=$trunk['trunk_status']?> trunk_no_<?=$trunk['id']?>">
					<a class="open-event" href="javascript:void(0);" title="<?=$this->MODULE->module_trunks->show_status_desc($trunk['id'],"origin")?>"><?=$this->MODULE->module_trunks->show_status_msg($trunk['id'],"origin")?></a>
				</td> 				
				<td class="module-8th status_<?=$trunk['trunk_status']?> trunk_no_<?=$trunk['id']?>">
					<button class="routing trunk_button_<?=$trunk['id']?>" name="<?=$trunk['id']?>" rel="<?=$trunk['trunk_status']?>">
						<span><?=lang('button_routing')?></span>
					</button>				
				</td> 								
				<td class="module-9th status_<?=$trunk['trunk_status']?> trunk_no_<?=$trunk['id']?>"> 		
					<button class="edit trunk_button_<?=$trunk['id']?>" name="<?=$trunk['id']?>" rel="<?=$trunk['trunk_status']?>">
						<span><?=lang('button_edit')?></span>
					</button>
				</td>		
				<td class="module-10th status_<?=$trunk['trunk_status']?> trunk_no_<?=$trunk['id']?>">
					<button class="options trunk_button_<?=$trunk['id']?> origin" id="<?=$trunk['id']?>" rel="<?=$trunk['trunk_status']?>" title="<?=$trunk['short_name']?>">
						<span class="trunk_button_span_<?=$trunk['id']?>">
							<?php if($trunk['trunk_status']){?>
								<?=lang('button_enabled')?>				
							<?php } else {?>
								<?=lang('button_disabled')?>
						<?php }?>
						</span>
					</button>
				</td> 				
			</tr> 
		<?php 
		$num++;}}?>
		</tbody> 
	</table> 		
    </div>    
</div>   
<div id="enable" title="<?=lang('term_confirm_action')?>">
	<p>
		<?=lang('text_are_you_sure_you_want_to_enable_trunk')?>
		<span class="trunk_name"></span>?
	</p>
</div>
<div id="disable" title="<?=lang('term_confirm_action')?>">
	<p>
		<?=lang('text_are_you_sure_you_want_to_disable_trunk')?>
		<span class="trunk_name"></span>?
	</p>
</div>